package com.lz.football.module.activity.openServe
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.TextField;
	
	public class OpenServeView extends BaseView implements IActivity
	{
		/**
		 *查看按钮
		 *  
		 */
		private var getBtn3:SimpleButton;
		
		/**
		 *领取智能大闯关奖励按钮 
		 */
		private var getBtn1:SimpleButton;
		/**
		 *领取英雄进阶奖励按钮 
		 */
		private var getBtn2:SimpleButton;
		
		private var _obj:Object;
		public function OpenServeView()
		{
			super();
		}
		
		
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.res.activity.openserveView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.openServeBg;
			_viewHeight = _windowBg.height;
			_viewWidth = _windowBg.width;
			
			getBtn3 = symbolSkin.getBtn3;
			getBtn1 = symbolSkin.getBtn1;
			getBtn2 = symbolSkin.getBtn2;
			symbolSkin.j_c.text =  "0/5";
			symbolSkin.j_r.text =  "0/5";
			symbolSkin.j_b.text =  "0/5";
			symbolSkin.f_j_c.visible = false;
			symbolSkin.f_j_r.visible = false;
			symbolSkin.f_j_b.visible = false;
			symbolSkin.f_z_o.visible = false;
			symbolSkin.f_z_c.visible = false;
			symbolSkin.f_h_c.visible = false;
			symbolSkin.f_h_r.visible = false;
			symbolSkin.f_h_b.visible = false;
			symbolSkin.f_h_g.visible = false;
			
			var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITYTIME_XML);
			
			var time:TextField = symbolSkin.time;
			time.text = "活动时间：" +xml.openServe + "截止";;
			
			isCloseBtn = true;
			isDrag = true;
			moveClose(_viewWidth - 30,32);
			onResizeHandler();
			addEvtListener();
			
		}
		override public function addEvtListener():void
		{
			super.addEvtListener();
			getBtn3.addEventListener(MouseEvent.CLICK,onLookHandler);
			getBtn1.addEventListener(MouseEvent.CLICK,onGetBtn1Hanlder);
			getBtn2.addEventListener(MouseEvent.CLICK,onGetBtn1Han2der);
		}
		
		/**
		 *领取英雄奖励 
		 * @param event
		 * 
		 */
		protected function onGetBtn1Han2der(event:MouseEvent):void
		{
			getBtn2.filters = filter;
			getBtn2.mouseEnabled = false;
			
			if(_obj.status6 == 1)
				_obj.status6 = 2;
			if(_obj.status7 == 1)
				_obj.status7 = 2;
			baseinformation(_obj);
			
			
			// TODO Auto-generated method stub
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_OPENSERVE_AWARD,{type:2}));
		}
		
		/**
		 *领取智能大闯关奖励 
		 * @param event
		 * 
		 */
		protected function onGetBtn1Hanlder(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			getBtn1.filters = filter;
			getBtn1.mouseEnabled = false;
			if(_obj.status12 == 5)
				_obj.status12 = 6;
			if(_obj.status13 == 5)
				_obj.status13 = 6;
			if(_obj.status14 == 5)
				_obj.status14 = 6;
			baseinformation(_obj);
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_OPENSERVE_AWARD,{type:1}));
		}
		
		/**
		 *查看 
		 * @param event
		 * 
		 */
		protected function onLookHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			getBtn3.filters = filter;
			getBtn3.mouseEnabled = false;
			if(_obj.status8 == 1)
				_obj.status8 = 2;
			if(_obj.status9 == 1)
				_obj.status9 = 2;
			if(_obj.status10 == 1)
				_obj.status10 = 2;
			if(_obj.status11 == 1)
				_obj.status11 = 2;
			baseinformation(_obj);
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_OPENSERVE_AWARD,{type:3}));
		}
		
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			getBtn3.removeEventListener(MouseEvent.CLICK,onLookHandler);
			getBtn1.removeEventListener(MouseEvent.CLICK,onGetBtn1Hanlder);
			getBtn2.removeEventListener(MouseEvent.CLICK,onGetBtn1Han2der);
		}
		
		override public function destroyView():void
		{
			removeEvtListener();
			super.destroyView();
		}
		
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE));
		}
		/**
		 *活跃度信息 
		 * @param $obj
		 * 
		 */
		public function baseinformation($obj:Object):void
		{
//			if(0)//完成绿色
//			{
//				symbolSkin.j_c.textColor = 0x00FF00
//				symbolSkin.j_r.textColor = 0x00FF00
//				symbolSkin.j_b.textColor = 0x00FF00
//			}else//未完成灰色
//			{
//				symbolSkin.j_c.textColor = 0x999999
//				symbolSkin.j_r.textColor = 0x999999
//				symbolSkin.j_b.textColor = 0x999999
//			}
			_obj = $obj;
			//智勇闯关
			if($obj.status6 == 2)//未完成 	过欧冠奖励
			{
				symbolSkin.f_z_o.visible = true;
			}else
			{
				symbolSkin.f_z_o.visible = false
			}
			if($obj.status7 == 2)//未完成	过传奇奖励
			{
				symbolSkin.f_z_c.visible = true;
			}else
			{
				symbolSkin.f_z_c.visible = false;
			}
			if($obj.status6 == 1 || $obj.status7 == 1)
			{
				getBtn2.mouseEnabled = true;
			}else
			{
				getBtn2.mouseEnabled = false;
				
				getBtn2.filters = filter;
			}
			
			
			
			
			if($obj.status8 == 2)//未完成 	洗橙奖励
			{
				symbolSkin.f_h_c.visible = true;
			}else
			{
				symbolSkin.f_h_c.visible = false
			}
			if($obj.status9 == 2)//未完成	洗红奖励
			{
				symbolSkin.f_h_r.visible = true;
			}else
			{
				symbolSkin.f_h_r.visible = false;
			}
			
			if($obj.status10 == 2)//未完成 	洗黑奖励
			{
				symbolSkin.f_h_b.visible = true;
			}else
			{
				symbolSkin.f_h_b.visible = false
			}
			if($obj.status11 == 2)//未完成	洗金奖励
			{
				symbolSkin.f_h_g.visible = true;
			}else
			{
				symbolSkin.f_h_g.visible = false;
			}
			if($obj.status8 == 1 || $obj.status9 == 1 || $obj.status10 == 1 || $obj.status11 == 1)
			{
				getBtn3.mouseEnabled = true;
			}else
			{
				getBtn3.mouseEnabled = false;
				getBtn3.filters = filter;
			}
			
			
			
			
			
			if($obj.status12 == 6)//完成
			{
				symbolSkin.j_c.textColor = 0x00FF00;
				symbolSkin.j_c.text = "5/5";
				symbolSkin.f_j_c.visible = true;
			}else
			{
				symbolSkin.j_c.textColor = 0x999999;
				symbolSkin.j_c.text = $obj.status12 + "/5";
				symbolSkin.f_j_c.visible = false;
				if($obj.status12 == 5)
					symbolSkin.j_c.textColor = 0x00FF00;
			}
			
			if($obj.status13 ==6)//完成
			{
				symbolSkin.j_r.textColor = 0x00FF00;
				symbolSkin.j_r.text = "5/5";
				symbolSkin.f_j_r.visible = true;
			}else
			{
				symbolSkin.j_r.textColor = 0x999999;
				symbolSkin.j_r.text = $obj.status13 + "/5";
				symbolSkin.f_j_r.visible = false;
				if($obj.status13 == 5)
					symbolSkin.j_r.textColor = 0x00FF00;
			} 
			
			if($obj.status14 ==6)//完成
			{
				symbolSkin.j_b.textColor = 0x00FF00;
				symbolSkin.j_b.text = "5/5";
				symbolSkin.f_j_b.visible = true;
			}else
			{
				symbolSkin.j_b.textColor = 0x999999;
				symbolSkin.j_b.text = $obj.status14 + "/5";
				symbolSkin.f_j_b.visible = false;
				if($obj.status14 == 5)
					symbolSkin.j_b.textColor = 0x00FF00;
			}
			
			if($obj.status12 == 5 || $obj.status13 == 5 || $obj.status14 == 5)
			{
				getBtn1.mouseEnabled = true;
			}else
			{
				getBtn1.mouseEnabled = false;
				getBtn1.filters = filter;
			}
			
		}
		private function get filter():Array
		{
			return [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
				0.3086, 0.6094, 0.082, 0, 0,
				0.3086, 0.6094, 0.082, 0, 0,
				0,0,0,1,0,])];
		}
		/**
		 *领取奖励返回  
		 * @param $obj
		 * 
		 */		
		public function award($obj:Object):void
		{
		}
	}
}